import { instance } from '../request'

const request = instance

/**
 * 新增访问受控ip列表记录
 * @param accessIp ip信息
 * @returns
 */
export const addAccessIpListApi = (accessIp: AccessIpItf): PromiseRes =>
  request.post(`/accessIpList/add`, accessIp)

/**
 * 批量删除受控 ip 项
 * @param ids 要删除的id列表
 * @returns
 */
export const deleteAccessIpListApi = (ids: string[]): PromiseRes =>
  request.post(`/accessIpList/delete`, ids)

/**
 * 批量设置受控 ip 项状态
 * @param ids id列表
 * @param enable 启用状态
 * @returns
 */
export const setIpsEnableStatusApi = (
  ids: string[],
  enable: 0 | 1
): PromiseRes => request.post(`/accessIpList/setEnable?enable=${enable}`, ids)

/**
 * 更新某个受控 ip 项信息
 * @param accessIp ip信息
 * @returns
 */
export const updateAccessIpListItemApi = (accessIp: AccessIpItf): PromiseRes =>
  request.post(`/accessIpList/update`, accessIp)

/**
 * 条件分页获取受控 ip 列表
 * @param accessIp ip信息
 * @param page 分页页码
 * @param size 分页大小
 * @returns
 */
export const getAccessIpListApi = (
  accessIp: AccessIpItf,
  page: number,
  size: number
): PromiseRes<PageResult<AccessIpItf>> =>
  request.post(`/accessIpList/getList?page=${page}&size=${size}`, accessIp)

/**
 * 获取某个类型的所有 ip
 * @param type 类型
 * @returns
 */
export const getAllIpByTypeApi = (
  type: 'Black' | 'White'
): PromiseRes<AccessIpItf[]> =>
  request.post(`/accessIpList/typeAll?type=${type}`)
